//
//  UIBarButtonItem+extension.swift
//  SwiftWeibo
//
//  Created by 刘英群 on 2016/12/25.
//  Copyright © 2016年 刘英群. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize：默认16号
    ///   - target:
    ///   - action: 
    ///   - isBackBtn: 是否是返回按钮，如果是，就加箭头
    convenience init(title: String, fontSize: CGFloat = 16, target: Any?, action: Selector, isBackBtn: Bool = false) {
        
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBackBtn {
            
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        //self.init 实例化 UIBarButtonItem
        self.init(customView: btn)
    }
}
